package com.xdl.moudle.shiro.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.xdl.moudle.shiro.domain.Menu;
import com.xdl.moudle.shiro.domain.Operation;
import com.xdl.moudle.shiro.domain.UserManager;
import com.xdl.moudle.shiro.service.iface.UserPermissionsService;
import com.xdl.moudle.shiro.util.BaseController;
import com.xdl.moudle.utils.util.apibase.APIBaseResult;

@RestController
@RequestMapping("sysUser")
public class UserController extends BaseController {

	@Autowired
	private UserPermissionsService userPermissionsService;
	
    @RequestMapping(value = "/queryPermissions", method = RequestMethod.POST)
    @ResponseBody
    public APIBaseResult queryPermissionList(String menuId) {
    	try {
    		UserManager user = super.getCurrentUser();
        	List<Operation> opeartionList = userPermissionsService.queryOperationByUid(user.getId(), menuId);
        	return APIBaseResult.success(opeartionList);
		} catch (Exception e) {
			e.printStackTrace();
			return APIBaseResult.error(e.getMessage());
		}
    }
    
    @RequestMapping(value = "/queryMenus", method = RequestMethod.POST)
    @ResponseBody
    public APIBaseResult queryMenuList() {
    	try {
    		UserManager user = super.getCurrentUser();
        	List<Menu> menuList = userPermissionsService.queryMenuByUid(user.getId());
        	return APIBaseResult.success(menuList);
		} catch (Exception e) {
			return APIBaseResult.error(e.getMessage());
		}
    }
}
